package com.planetarium.objects;

import java.awt.Graphics;
import java.awt.Rectangle;

public class DummySystem implements PlanetarySystem {
	
	private BasicObject[] objects = new BasicObject[2];
    private double diameter;
	
	public DummySystem() {
		objects[0] = new DummyCenter();
		objects[1] = new DummyOrbiter();
		
        diameter = getSolarSystemDiameter();
	}
	
	/*
	 * 
	 * Renders the solar-system inside the boundaries
	 * specified by the boundaries parameter on the
	 * canvas given by the g parameter.
	 * 
	 */
	
    public void render(Graphics g, Rectangle boundaries) {
        double centerX = boundaries.getCenterX();
        double centerY = boundaries.getCenterY();
        double width = boundaries.getWidth();
        double height = boundaries.getHeight();
        double reduceFraction;
        int screenX, screenY, screenR;
        
        if (width > height)
            reduceFraction = diameter / height;
        else
            reduceFraction = diameter / width;
        
        for (int i = 0; i < objects.length; i++) {
            screenX = (int) (centerX + (objects[i].position.x / reduceFraction));
            screenY = (int) (centerY + (objects[i].position.y / reduceFraction));
            screenR = (int) (objects[i].radius / reduceFraction);
            
            objects[i].render(g, screenX, screenY, screenR);
        }
    }
    
    /*
     * 
     * Updates the current system and
     * recomputes the planetary orbit parameters.
     * 
     */
    
    public void update() {
    	
    }
    
    /*
     * 
     * Gets the diameter of the solar-system,
     * which is twice the measured radius of the
     * outermost orbit radius.
     * 
     */
    
    private double getSolarSystemDiameter() {
        double maxRadius = 0, currentRadius;
        
        for (int i = 0; i < objects.length; i++) {
            currentRadius = objects[i].position.length() + objects[i].radius;
            
            if (currentRadius > maxRadius)
                maxRadius = currentRadius;
        }
        
        return maxRadius * 2;
    }
	
}
